From dc824c0ac704b35130aff44e544e8666e21b5bc5 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 18 Jun 2012 15:17:51 +0200 Subject: [PATCH] Add simple test app to test pow-24 accuracy https://bugzilla.gnome.org/show_bug.cgi?id=678318 --- babl/base/Makefile.am | 4 ++++ babl/base/test-pow.c | 54 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 babl/base/test-pow.c diff --git a/babl/base/Makefile.am b/babl/base/Makefile.am index 5b92521..58f711e 100644 --- a/babl/base/Makefile.am +++ b/babl/base/Makefile.am @@ -27,3 +27,7 @@ EXTRA_DIST = \ util.h \ pow-24.h +noinst_PROGRAMS = test-pow + +test_pow_SOURCES = test-pow.c +test_pow_LDADD = libbase.la $(MATH_LIB) diff --git a/babl/base/test-pow.c b/babl/base/test-pow.c new file mode 100644 index 0000000..08406c9 --- /dev/null +++ b/babl/base/test-pow.c @@ -0,0 +1,54 @@ +#include +#include + +#include "pow-24.h" + +int +main (int argc, char *argv[]) +{ + double s, r1, r2, diff, max; + double at_s, at_r1, at_r2; + long i; + + s = 0.03; + at_s = 0; + max = 0; + for (i = 0; i < 1100000000; i++) + { + r1 = babl_pow_24 (s); + r2 = pow (s, 2.4); + diff = fabs (r2-r1); + if (diff > max) { + max = diff; + at_s = s; + at_r1 = r1; + at_r2 = r2; + } + s += 0.000000001; + } + printf ("x^2.4\n"); + printf ("max from 0 to %f is %e\n", s, max); + printf ("at: %f %f %f\n", at_s, at_r1, at_r2); + + s = 0.03; + at_s = 0; + max = 0; + for (i = 0; i < 1100000000; i++) + { + r1 = babl_pow_1_24 (s); + r2 = pow (s, 1/2.4); + diff = fabs (r2-r1); + if (diff > max) { + max = diff; + at_s = s; + at_r1 = r1; + at_r2 = r2; + } + s += 0.000000001; + } + printf ("x^(1/2.4)\n"); + printf ("max from 0 to %f is %e\n", s, max); + printf ("at: %f %f %f\n", at_s, at_r1, at_r2); + + return 0; +} -- 2.30.2